import { defineStore } from 'pinia'
export const useUserCate = defineStore('user', {
    state: () => {
        return {
            token: '',
            userinfo: {
                'id': 0,
                'name': '',
                'icon': '',
                'subjectCount': '',
                'showStatus': '',
                'sort': ''
            }
        }
    },
    getters: {
        getToken() {
            return this.token;
        }
    },
    actions: {
        /**
         * token赋值
         * @param {*} token 
         */
        setToken(token) {
            this.token = token
        },
        /**
         * 填充用户数据
         * @param {*} user 
         */
        fillUserinfo(user) {
            this.userinfo = user
        }
    },
    persist: {
        enabled: true,
        strategies: [
            {
                key: 'userinfo',
                storage: localStorage, //会话存储 sessionStorage 本地存储：localStorage
                paths: ['token', 'userinfo']
            }
        ]
    }
})